package com.red.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.red.entity.Stock;
import com.red.entity.StockProduct;
import com.red.result.Result;
import com.red.service.StockService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/stock")
public class StockController {
    @Autowired
    private StockService stockService;

    @ApiOperation("根据条件查询进货单")
    @ApiImplicitParam(name = "odd",value = "进货单单号")
    @GetMapping("/select")
    public Result findAll(String odd){
        return new Result(
                stockService.list(
                        new QueryWrapper<Stock>()
                                .like(odd!=null,"odd",odd)
                )
        );
    }

    @ApiOperation("添加进货单")
    @PostMapping("/save")
    public Result save(Stock stock){

        return new Result(stockService.save(stock)
        );
    }

    @ApiOperation("修改进货单")
    @PutMapping("/update")
    public Result update(Stock stock){
        return new Result(stockService.updateById(stock));
    }

    @ApiOperation("删除进货单")
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        return  new Result(stockService.removeById(id));
    }
}
